package demo.druid.servlet;

import demo.druid.dao.TipDao;
import demo.druid.entity.Tip;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

@WebServlet(name = "ServletInserTestDruid", value = "/DruidAdd")
public class ServletInserTestDruid extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 新增
        Tip tip = new Tip(3, "yang同学", 20,
                2, new Date(), "goodstudy,daydayup");
        TipDao tipDao = new TipDao();
        tipDao.add(tip);

        // 查询
        List<Tip> list = tipDao.select("同学");
        PrintWriter out = response.getWriter();
        for (Tip t : list) {
            out.print(t);
            out.print("</br>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }
}
